//
//  MsgParam.m
//  QBIM
//
//  Created by liunian on 14-3-17.
//  Copyright (c) 2014年 liunian. All rights reserved.
//

#import "MsgParam.h"
#import "ProtocolConfig.h"

@interface MsgParam ()
{
    NSMutableString *thredString;
}

@end

@implementation MsgParam

- (void)setMessageType:(MTPacketType)messageType{
    QB_SET_RETAIN_NUMPARM(messageType, @"messageType");
}
- (void)setFromid:(int)fromid{
    QB_SET_RETAIN_NUMPARM(fromid, @"fromid");
}

- (void)setToid:(int)toid{
    QB_SET_RETAIN_NUMPARM(toid, @"toid");
}
- (void)setSubtype:(PacketSubtypeType)subtype{
    QB_SET_RETAIN_NUMPARM(subtype, @"subtype");
}

- (void)setAtid:(int)atid{
    QB_SET_RETAIN_NUMPARM(atid, @"atid");
}

- (void)setContenttype:(PacketContentType)contenttype{
    QB_SET_RETAIN_NUMPARM(contenttype, @"contenttype");
}
- (void)setMessage:(NSString *)message{
    QB_SET_RETAINPARM(message, @"message");
}

//thread是由messageType:masterId:slaveId几个字段组合而成的一段字符串，
- (NSString *)thread{
    thredString = [[[NSMutableString alloc] init] autorelease];
    MTPacketType type = self.messageType;
    
    //masterId
    [thredString appendFormat:@"%d",type];
    if (type == MTPacketTypeSys || type == MTPacketTypePublic) {
        [thredString appendFormat:@":%d", self.fromid];
    }else if(type == MTPacketTypeGroup) {
        [thredString appendFormat:@":%d",self.fromid];
    
    }else if(type == MTPacketTypePrivate) {
        [thredString appendFormat:@":%d",self.fromid< self.toid ? self.fromid : self.toid];
        
    }
    
    //slaveId
    if (type == MTPacketTypeSys || type == MTPacketTypeGroup) {
        [thredString appendString:@":0"];
    }else if(type == MTPacketTypeGroup) {
        [thredString appendString:@":0"];
        
    }else if(type == MTPacketTypePrivate) {
        [thredString appendFormat:@":%d",self.fromid > self.toid? self.fromid : self.toid];
        
    }
    return thredString;
}
@end
